﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace ESHOP.ADMIN.Common
{
    public class CommonFunc
    {
        public static void BindDropDownList(DropDownList dropDownList, object dataSource, string dataTextField, string dataValueField, bool addFirstItem)
        {
            if (dataSource == null) return;

            dropDownList.DataTextField = dataTextField;
            dropDownList.DataValueField = dataValueField;
            dropDownList.DataSource = dataSource;
            dropDownList.DataBind();

            if (!addFirstItem) return;

            var _arrSort = new ListItem[dropDownList.Items.Count + 1];
            _arrSort[0] = new ListItem("Tất cả", "%");
            for (var _li = 0; _li < _arrSort.Length - 1; _li++) { _arrSort[_li + 1] = dropDownList.Items[_li]; }
            dropDownList.Items.Clear();
            dropDownList.Items.AddRange(_arrSort);
        }
        public static string UniqueIDWithDollars(Control ctrl)
        {

            var sId = ctrl.UniqueID;
            if (sId == null)
            {
                return null;
            }

            if (sId.IndexOf(':') >= 0)
            {
                return sId.Replace(':', '$');
            }

            return sId;

        }
    }
}